/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.dispositivos;

import com.mapping.Dispositivo;
import com.opensymphony.xwork2.ActionSupport;
import static com.opensymphony.xwork2.Action.SUCCESS;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author Andres
 */
@Namespace(value="/")
@Action(value="buscarNoserie", results={@Result(name="success",location="/GestionDispositivos/rBuscarNoserie.jsp")})
public class BuscarNoserieAction extends ActionSupport{
    String modelo;
    private List<Dispositivo> listaDispositivo;
    
    @Override 
    public String execute(){
        String consulta = "select IDDISP,NOSERIE,LOCALIZACION,ESTADO,IDMODELO from dispositivo where idModelo=?1";
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em =  emf.createEntityManager();  
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        Query query =  em.createNativeQuery(consulta,Dispositivo.class);
        query.setParameter(1,modelo);
        listaDispositivo = (List<Dispositivo>) query.getResultList();
        tx.commit();
        em.close();
        
        return SUCCESS;
    }

    public void setModelo(String modelo) {
        this.modelo = modelo;
    }

    public List<Dispositivo> getListaDispositivo() {
        return listaDispositivo;
    }
}
